package com.dd.ms.nacos.controller;

import com.dd.ms.common.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/2/23 16:48
 * @Description 提供该模块本身的信息 用作测试
 */
@Slf4j
@RefreshScope // 支持配置动态刷新
@RestController
@RequestMapping("/nacos")
@Api(tags = "提供该模块本身的信息 用作测试")
public class InfoProviderController {

    @Value("${spring.cloud.nacos.config.server-addr}")
    private String configValue;

    @Value("${spring.datasource.url}")
    private String dataSourceUrl;

    @Value("${extended-config1.ec-id}")
    private String extendedConfig1EcId;

    @Value("${extended-config2.ec2-name}")
    private String extendedConfig2Ec2Name;

    @GetMapping("/addr")
    public ApiResponse<String> nacosAddr() {
        return ApiResponse.success("Hello from Nacos! Config value: " + configValue);
    }

    @GetMapping("/spring/datasource/url")
    public ApiResponse<String> dataSourceUrl() {
        System.out.println(dataSourceUrl);
        return ApiResponse.success("dataSourceUrl: " + dataSourceUrl);
    }

    @GetMapping("/extendedConfig1EcId")
    @ApiOperation("获取拓展配置1的id属性,支持动态刷新")
    public ApiResponse<String> extendedConfig1EcId() {
        return ApiResponse.success(extendedConfig1EcId);
    }

    @GetMapping("/extendedConfig2Ec2Name")
    @ApiOperation("获取拓展配置2的name属性,不支持动态刷新")
    public ApiResponse<String> extendedConfig2Ec2Name() {
        return ApiResponse.success(extendedConfig2Ec2Name);
    }
}
